import Timeline from "vux/src/components/timeline/timeline.vue";
import TimelineItem from "vux/src/components/timeline/timeline-item.vue";
import dateFormat from "vux/src/tools/date/format.js";

import { mapGetters, mapActions } from "vuex";

import template from "./whdProgressTemplate";
const { render, staticRenderFns } = template;

export default {
  render,
  staticRenderFns,
  filters: {
    dateFormat,
  },
  components: {
    Timeline,
    TimelineItem,
  },
  data() {
    return {
      color: 1,
      presentState: {},
      cash_id: 0,
    };
  },
  computed: {
    ...mapGetters(["accountData", "userInfo"]),
  },
  created() {
    this.cash_id = this.$route.query.cash_id;
    console.log(this.accountData);
    this.wthdMsg();
  },
  methods: {
    ...mapActions(["SET_ACCOUNT_DATA"]),
    wthdMsg() {
      let vm = this;
      let params = {};
      params.token = localStorage.getItem("token");
      params.cash_id = vm.cash_id;
      vm.$vux.loading.show();
      vm.$http
        .post(vm.urlRequest + "?m=api&c=cash&a=presentState", params)
        .then((res) => {
          if (res.status == 0) {
            vm.presentState = res;
            if (vm.presentState.type == 2 || vm.presentState.type == 3) {
              vm.color = 1;
            } else {
              vm.color = 2;
            }
          }
          vm.$vux.loading.hide();
        })
        .catch((err) => {
          vm.$vux.loading.hide();
          console.log(err);
        });
    },
  },
  beforeDestroy() {
    if (
      this.presentState.type == 1 ||
      this.presentState.type == 2 ||
      this.presentState.type == 3
    ) {
      let temp = this.accountData;
      temp.cash_id = 0;
      this.cash_id = 0;
      this.SET_ACCOUNT_DATA({
        Obj: temp,
      });
    }
  },
};

// WEBPACK FOOTER //
// ./src/components/wallet/withdraw/whdProgress.vue
